home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Cuadros de diálogo / ImageOpen / ImageOpen.cs next >
Encoding:
Text File  |  2002-05-23  |  2.5 KB  |  72 lines

  1. //----------------------------------------
  2. // ImageOpen.cs ⌐ 2001 by Charles Petzold
  3. //----------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Windows.Forms;
  8.  
  9. class ImageOpen: Form
  10. {
  11.      protected string strProgName;
  12.      protected string strFileName;
  13.      protected Image  image;
  14.  
  15.      public static void Main()
  16.      {
  17.           Application.Run(new ImageOpen());
  18.      }
  19.      public ImageOpen()
  20.      {
  21.           Text = strProgName = "Abrir imagen";
  22.           ResizeRedraw = true;
  23.  
  24.           Menu = new MainMenu();
  25.           Menu.MenuItems.Add("&Archivo");
  26.           Menu.MenuItems[0].MenuItems.Add(new MenuItem("&Abrir...", 
  27.                                    new EventHandler(MenuFileOpenOnClick),
  28.                                    Shortcut.CtrlO));
  29.      }
  30.      void MenuFileOpenOnClick(object obj, EventArgs ea)
  31.      {
  32.           OpenFileDialog dlg = new OpenFileDialog();
  33.  
  34.           dlg.InitialDirectory = "c:\\" ;
  35.  
  36.           dlg.Filter = "Todos los archivos de imßgenes|*.bmp;*.ico;*.gif;*.jpeg;*.jpg;" +
  37.                               "*.jfif;*.png;*.tif;*.tiff;*.wmf;*.emf|" +
  38.                        "Mapa de bits de Windows (*.bmp)|*.bmp|" +
  39.                        "Icono de Windows (*.ico)|*.ico|" +
  40.                        "Formato de intercambio de grßficos (*.gif)|*.gif|" +
  41.                        "Formato de intercambio de archivos JPEG (*.jpg)|" +
  42.                               "*.jpg;*.jpeg;*.jfif|" +
  43.                        "Grßficos de red portables (*.png)|*.png|" +
  44.                        "Formato de archivo de marcas de imßgenes (*.tif)|*.tif;*.tiff|" +
  45.                        "Metarchivo de Windows (*.wmf)|*.wmf|" +
  46.                        "Metarchivo mejorado (*.emf)|*.emf|" +
  47.                        "Todos los archivos (*.*)|*.*";
  48.  
  49.           if (dlg.ShowDialog() == DialogResult.OK)
  50.           {    
  51.                try
  52.                {
  53.                     image = Image.FromFile(dlg.FileName);
  54.                }
  55.                catch (Exception exc)
  56.                {
  57.                     MessageBox.Show(exc.Message, strProgName);
  58.                     return;
  59.                }
  60.                strFileName = dlg.FileName;
  61.                Text = strProgName + " - " + Path.GetFileName(strFileName);
  62.                Invalidate();
  63.           }
  64.      }
  65.      protected override void OnPaint(PaintEventArgs pea)
  66.      {
  67.           Graphics grfx = pea.Graphics;
  68.  
  69.           if (image != null)
  70.                grfx.DrawImage(image, 0, 0);
  71.      }
  72. }